<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>text</title>
</head>
<body>
<div id="div">
    {{name}}
    <button @click="send();">发送请求</button>
</div>
</body>
<script src="js/vue.js"></script>
<script src="js/axios-0.18.0.js"></script>
<script>
    new Vue({
        el:"#div",
        data:{
            name:"张三"
        },
        methods:{
            send(){
                /*axios.get("/testServlet?name="+this.name)
                    //箭头函数，内部的this代表当前的vue对象
                .then(resp=>{
                    this.name=resp.data;
                })*/
                /*axios.post("/testServlet","name="+this.name)
                    .then(resp=>{
                    //箭头函数，内部的this代表当前的vue对象
                        this.name=resp.data;
                });*/
                axios.post("/testServlet",{name:this.name})
                    .then(resp=>{
                        //箭头函数，内部的this代表当前的vue对象
                        alert(resp.data)
                        // this.name=resp.data;
                    });
            }
        }

    });
</script>
</html>